/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.ui.function.window.main;

import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;

import lineage.ui.combination.L1List;
import lineage.ui.function.window.secretchat.L1WindowSecretChat;
import lineage.util.Util;

/**
 * 在线角色列表框.
 * 
 * @version 2014年2月25日下午1:20:39
 * @author jrwz
 */
public final class L1BoxListOnlinePc extends L1List {
    private static final long serialVersionUID = -8449091609490709250L;

    /**
     * 静态初始化器，由JVM来保证线程安全.
     */
    private static class Holder {
        static L1BoxListOnlinePc instance = new L1BoxListOnlinePc();
    }

    /**
     * 取得该类的实例.
     */
    public static L1BoxListOnlinePc getInstance() {
        return Holder.instance;
    }

    private L1BoxListOnlinePc() {
        _x = 1;
        _y = 0;
        _width = 172;
        _height = 420;
        menuitemstr = new String[] { "开启私聊", "踢出游戏", "封锁IP", "查看资料" };

        init(true);
    }

    @Override
    protected void addListModel() {
        super.addListModel();
        // 测试
        // 名称,提示信息,图片
        listModel.addElement(new Object[] { "王", "这是王", getProfession("王") });
        listModel.addElement(new Object[] { "骑", "这是骑", getProfession("骑") });
        listModel.addElement(new Object[] { "妖", "这是妖", getProfession("妖") });
        listModel.addElement(new Object[] { "法", "这是法", getProfession("法") });
        listModel.addElement(new Object[] { "黑", "这是黑", getProfession("黑") });
        listModel.addElement(new Object[] { "龙", "这是龙", getProfession("龙") });
        listModel.addElement(new Object[] { "幻", "这是幻", getProfession("幻") });
        listModel.addElement(new Object[] { "GM", "这是GM", getProfession("GM") });
        // end
    }

    @Override
    protected void addList() {
        super.addList();
        list.setOpaque(false); // 透明
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 鼠标左键点击
        if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
            String str = e.getActionCommand();
            Object selected = list.getModel().getElementAt(list.getSelectedIndex());
            Object[] cell = (Object[]) selected;
            switch (str) {
            case "开启私聊":
                L1WindowSecretChat.getInstance().set(cell);
                break;
            default:
                break;
            }
            Util.message(cell[0] + ":" + str);
        }
    }

    /**
     * 取得各职业对应的mark图像.
     * 
     * @param type
     *            - 职业类型
     * @return 职业对应的图像名称(带完整相对路径名)
     */
    private String getProfession(String type) {
        StringBuilder sb = new StringBuilder();
        switch (type) {
        case "王":
            sb.append("./image/mark/Crown.png");
            break;
        case "骑":
            sb.append("./image/mark/Knight.png");
            break;
        case "妖":
            sb.append("./image/mark/Elf.png");
            break;
        case "法":
            sb.append("./image/mark/Wizard.png");
            break;
        case "黑":
            sb.append("./image/mark/Darkelf.png");
            break;
        case "龙":
            sb.append("./image/mark/DragonKnight.png");
            break;
        case "幻":
            sb.append("./image/mark/Illusionist.png");
            break;
        default:
            sb.append("./image/mark/null.png");
            break;
        }
        return sb.toString();
    }
}
